package com.tanhua.server.controller;

import com.tanhua.common.utils.Cache;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.common.vo.ErrorResult;
import com.tanhua.server.service.RecommendationService;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 王加鑫
 * @Date 2021/09/03 19:17
 * @Since JDK 1.8
 */
@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    @Autowired
    private RecommendationService recommendationService;

    /**
     * 查询今日佳人
     */
    @GetMapping("todayBest")
    public ResponseEntity<Object> queryTodayBest(){
        try {
            TodayBest todayBest = todayBestService.queryTodayBest();
            return ResponseEntity.ok(todayBest);
        } catch (Exception e) {
            log.error("查询今日佳人失败 userId = " + UserThreadLocal.get().getId(),e);
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("查询今日佳人失败").build();
        return ResponseEntity.status(500).body(errorResult);
    }

    /**
     * 查询推荐用户(集合数据)
     * @return
     */
    @GetMapping("recommendation")
    @Cache
    public ResponseEntity<Object> queryRecommendation(RecommendUserQueryParam param){
        try {
            PageResult pageResult = recommendationService.queryRecommendation(param);
            return ResponseEntity.ok(pageResult);
        } catch (Exception e) {
            log.error("查询推荐用户失败 userId = " + UserThreadLocal.get().getId(),e);
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("查询推荐用户失败").build();
        return ResponseEntity.status(500).body(errorResult);
    }
}
